package com.h3c.gm.controller

import com.h3c.gm.common.Response
import com.h3c.gm.entity.VO.BusOrgVO
import com.h3c.gm.service.BusHostSpecService
import com.h3c.gm.service.BusOrgService
import com.h3c.gm.service.BusUserService
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RestController

import javax.annotation.Resource

/**
 * Created by d14287 on 2017/6/26.
 */
@RestController
class BusOrgController {
    @Resource
    BusOrgService orgService
    @Resource
    BusHostSpecService busHostSpecService
    /**
     * 获取全国学校总数
     * @return
     */
    @RequestMapping(value = 'org/count', method = RequestMethod.GET)
    def getCount() {
        def response = new Response()
        response.ofSuccess(orgService.getCount())
    }
    /**
     * 获取省份学校总数
     * @param province
     * @return
     */
    @RequestMapping(value = 'org/procount/{province}', method = RequestMethod.GET)
    def getProCount(@PathVariable(name = 'province') String province) {
        def response = new Response()
        response.ofSuccess(orgService.getProCount(province))
    }

    /**
     * 获取学校列表
     * @return
     */
    @RequestMapping(value = 'org/orgs', method = RequestMethod.GET)
    def getOrgs() {
        def response = new Response()
        List<BusOrgVO> busOrgVOList = orgService.getOrgs()
        busOrgVOList.each {
            item ->
                item.setHostcount(busHostSpecService.getCountByOrgkey(item.getOrgkey()))
        }
        response.ofSuccess(busOrgVOList)
    }

    /**
     * 获取学校
     * @return
     */
    @RequestMapping(value = 'org/org/{orgkey}', method = RequestMethod.GET)
    def getOrg(@PathVariable(name = 'orgkey') String orgkey) {
        def response = new Response()
        response.ofSuccess(orgService.getOrg(orgkey))
    }

    /**
     * 获取全省学校列表
     * @param province
     * @return
     */
    @RequestMapping(value = 'org/proorgs/{province}', method = RequestMethod.GET)
    def getProOrgs(@PathVariable(name = 'province') String province) {
        def response = new Response()
        def busOrgVOList = orgService.getProOrgs(province)
        busOrgVOList.each {
            item ->
                item.setHostcount(busHostSpecService.getCountByOrgkey(item.getOrgkey()))
        }
        response.ofSuccess(busOrgVOList)
    }

    /**
     * 获取Map<市-学校>数据
     * @return
     */
    @RequestMapping(value = 'org/cityorgs', method = RequestMethod.GET)
    def getCityOrgs() {
        def response = new Response()
        response.ofSuccess(orgService.getCityOrgs())
    }

    /**
     * 按省获取学校列表
     * @param city
     * @return
     */
    @RequestMapping(value = 'org/cityorg/{city}', method = RequestMethod.GET)
    def getCityOrg(@PathVariable(name = 'city') String city) {
        def response = new Response()
        response.ofSuccess(orgService.getCityOrg(city))
    }

}
